package com.jzo2o.customer.service.impl;

import com.jzo2o.common.utils.BeanUtils;
import com.jzo2o.common.utils.UserContext;
import com.jzo2o.customer.model.domain.BankAccount;
import com.jzo2o.customer.mapper.BankAccountMapper;
import com.jzo2o.customer.model.dto.request.BankAccountUpsertReqDTO;
import com.jzo2o.customer.model.dto.response.BankAccountResDTO;
import com.jzo2o.customer.service.IBankAccountService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 * 银行账户 服务实现类
 * </p>
 *
 * @author zhq
 * @since 2025-09-18
 */
@Service
public class BankAccountServiceImpl extends ServiceImpl<BankAccountMapper, BankAccount> implements IBankAccountService {

    @Override
    public void addAccount(BankAccountUpsertReqDTO bankAccountUpsertReqDTO) {
        BankAccount bankAccount = BeanUtils.copyBean(bankAccountUpsertReqDTO, BankAccount.class);
        bankAccount.setCreateTime(LocalDateTime.now());
        bankAccount.setUpdateTime(LocalDateTime.now());
        this.saveOrUpdate(bankAccount);
    }

    @Override
    public BankAccountResDTO getCurrentUserBankAccount() {
        Long l = UserContext.getCurrentUser().getId();
        BankAccount bankAccount = baseMapper.selectById(l);
        if(bankAccount == null){
            return null;
        }
        BankAccountResDTO bankAccountResDTO = BeanUtils.copyBean(bankAccount, BankAccountResDTO.class);
        return bankAccountResDTO;
    }
}

